package com.zudada.servermain.controller.portmanage;

import com.zudada.servermain.POJO.DTO.PortUserPageQueryDTO;
import com.zudada.servermain.POJO.DTO.VesselBerthingAddDTO;
import com.zudada.servermain.POJO.DTO.VesselBerthingPageQueryDTO;
import com.zudada.servermain.POJO.DTO.VesselBerthingUpdateDTO;
import com.zudada.servermain.POJO.VO.PageResult;
import com.zudada.servermain.POJO.enums.Result;
import com.zudada.servermain.Service.VesselBerthingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Slf4j
@RestController
@Api(tags="船舶停靠数据接口")
@RequestMapping("/vessel-berthing")
public class VesselBerthingController {

    @Autowired
    private VesselBerthingService vesselBerthingService;

    /**
     * 添加船舶停靠数据
     * @param dto
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("添加船舶停靠数据")
    public Result<Boolean> addVesselBerthing(@Valid @RequestBody VesselBerthingAddDTO dto) {
        log.info("添加船舶停靠数据");
        boolean result = vesselBerthingService.addVesselBerthing(dto);
        return result ? Result.success(true) : Result.error("添加失败");
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/delete")
    @ApiOperation("删除船舶停靠数据")
    public Result<String>delVesselBerthing(String id){
        log.info("删除船舶停靠数据，{}",id);
        boolean success = vesselBerthingService.deleteById(id);
        if(success){
            return Result.success("港口数据删除成功");
        }else {
            return Result.error("港口数据删除失败");
        }
    }

    /**
     * 修改船舶停靠数据
     * @param DTO
     * @return
     */
    @PutMapping("/update")
    @ApiOperation("修改船舶停靠数据")
    public Result<String> updateVesselBerthing(@RequestBody VesselBerthingUpdateDTO DTO){
        log.info("修改船舶停靠数据{}",DTO);
        vesselBerthingService.updateVesselBerthing(DTO);
        return Result.success();

    }


    /**
     * 船舶停靠数据分页查询
     * @param queryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("船舶停靠数据分页查询")
    public Result<PageResult> page(VesselBerthingPageQueryDTO queryDTO){
        log.info("分页查询：{}",queryDTO);
        PageResult pageResult = vesselBerthingService.pageQuery(queryDTO);
        return Result.success(pageResult);
    }



}
